<template>
  <div>
    <el-form
      :model="account"
      ref="form"
      label-width="80px"
      :inline="false"
      size="default"
    >
      <el-form-item label="账号">
        <el-input v-model="account.username"></el-input>
      </el-form-item>
      <el-form-item label="密码">
        <el-input v-model="account.password"></el-input>
      </el-form-item>
      <el-form-item label="角色">
        <el-select
          v-model="account.roleId"
          value-key=""
          placeholder=""
          clearable
          filterable
          @change=""
        >
          <el-option
            v-for="item in roleList"
            :key="item.objectId"
            :label="item.name"
            :value="item.objectId"
          >
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="onSubmit">立即新增</el-button>
        <el-button>取消</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script setup lang="ts">
import { reactive, ref } from "vue";
import { AccountType, RoleType } from "../../../types/user";
import { roleGet, userReg } from "../../../api/user";
const account: AccountType = reactive({
  username: "",
  password: "",
  roleId: "",
});
const onSubmit = () => {
  //分配账号
  userReg(account);
};

const roleList = ref<Array<RoleType>>([]);
const res = await roleGet();
roleList.value = res.data.results;
</script>

<style scoped></style>
